package control;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import dao.UsuarioProjetoDAO;

public class RespondeRequisicaoAction extends Action {
	
	public ActionForward execute(ActionMapping map, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws SQLException {
		
		//Dados do JSP
		String usuario = request.getParameter("usuario");
		String nomeUnix = request.getParameter("nomeUnix");
		String resposta = request.getParameter("resposta");
		
		String action = "";
		
		Facade facade = Facade.getInstance();
		
		//UsuarioProjetoDAO daoUP = UsuarioProjetoDAO.getInstance();
		//requisicao eh negada
		if (resposta.equals("nao")) {
			facade.removeUsuarioRequisicao(usuario, nomeUnix);
//			daoUP = UsuarioProjetoDAO.getInstance();
//			daoUP.remove(usuario, nomeUnix);
			action = "requisicao_negada";
		}
		//requisicao eh aceita
		else {
			facade.aceitaUsuarioRequisicao(usuario, nomeUnix, true);
			action = "requisicao_aceita";
		}
		return map.findForward(action);
	}
}